<?php
/**
 * GioCMS
 * 
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2 
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@ninhgio.com so we can send you a copy immediately.
 * 
 * @copyright	Copyright (c) 2010-2011 GioCMS (http://cms.ninhgio.com)
 * @license		http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @author		NinhGio - ninhgio@gmail.com
 * @since		1.0
 */

class Modules_Core_Services_LinkProvider
{	
	public static function getLinks($lang = null)
	{
		if (null == $lang) {
			$lang = Gio_Core_Config_Xml::getConfig('web')->language;
		}
		
		$view 	= Gio_Core_View::getInstance();
		$router = Gio_Core_Route::getInstance(); 
		
		$results = array();		
		$links   = array();
		
		/**
		 * Add the homepage link
		 */
		$links['core_index_index'][] = array(
			'href' => $view->url('core_index_index', array('language' => $lang)),
		);
		
		$links = Gio_Core_Hook_Registry::getInstance()->executeFilter('Core_LinkProvider', $links, array($lang));
		foreach ($links as $routeName => $value) {
			/**
			 * Get route description
			 */
			$defaults    		 = $router->getRoute($routeName);
			$description 		 = isset($defaults['langKey'])
									? $view->TRANSLATOR->translator($defaults['langKey'], $defaults['module'], $lang)
									: $routeName;
			$results[$routeName] = array(
										'description' => $description,
										'links'		  => $value,
									);
		}
		
		return $results;
	}
}